package com.shouhe.mysap.controller.finance;

import com.shouhe.mysap.common.MySapResult;
import com.shouhe.mysap.common.PageResult;
import com.shouhe.mysap.common.status.PurStatus;
import com.shouhe.mysap.entity.PurPrice;
import com.shouhe.mysap.service.PurPriceService;
import com.shouhe.mysap.util.PageResultUtil;
import com.shouhe.mysap.util.SelectUtil;
import com.shouhe.mysap.util.UpdateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @author 守鹤
 * @create 2020-06-11 21:50
 */
@RestController
@RequestMapping("/financeCheckPurPrice")
public class FinanceCheckPurPriceController {

    @Autowired
    private PurPriceService purPriceService;

    /**
     * @描述 得到全部的采购人员
     * @参数
     * @返回值
     */
    @RequestMapping("/getPurPrices")
    public PageResult getPurPrices(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer rows) {
        PageResult pageResult = PageResultUtil.getPageResultEq(page, rows, purPriceService,"status","0");
        return pageResult;
    }



    /**
     * @描述 得到全部的采购人员
     * @参数
     * @返回值
     */
    @RequestMapping("/checkPurPrice")
    public MySapResult checkPurPrice(@RequestParam("ids[]") Integer[] ids) {
        List<PurPrice> purPrices = SelectUtil.selectListIn("id", Arrays.asList(ids), purPriceService);
        for (PurPrice purPrice : purPrices) {
            purPrice.setStatus(PurStatus.PUR_PRICE_FINANCE_HAS_CHECK);
        }
        MySapResult result = UpdateUtil.updateObjectListById("财务审核采购价格", purPrices, purPriceService);
        return result;
    }





}
